{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "8\n"
     ]
    }
   ],
   "source": [
    "import random\n",
    "# number = range(0,10) + range(11,20)\n",
    "number = []\n",
    "for i in range(0,10):\n",
    "    number.append(i)\n",
    "for i in range(11,20):\n",
    "    number.append(i)\n",
    "x = random.choice(number)\n",
    "print(x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[('127.0.0.1', 11052), ('127.0.0.1', 11252), ('127.0.0.1', 11452), ('127.0.0.1', 11652)]\n"
     ]
    }
   ],
   "source": [
    "import traceback\n",
    "\n",
    "\n",
    "test_tatget = 1 # test shadr id 0\n",
    "shard = 4\n",
    "id =  0 \n",
    "\n",
    "        # address is the id of targett shard\n",
    "addresses = [None] * shard\n",
    "try:\n",
    "    with open('hosts.config', 'r') as hosts:\n",
    "        for line in hosts:\n",
    "            params = line.split()\n",
    "            pid = int(params[0])\n",
    "            priv_ip = params[1]\n",
    "            pub_ip = params[1]\n",
    "            port = int(params[2])\n",
    "            # print(pid, ip, port)\n",
    "            if pid not in range(shard):\n",
    "                continue\n",
    "            if pid == id:\n",
    "                my_address = (priv_ip, port)\n",
    "            for _ in range((test_tatget*shard), (test_tatget+1)*shard):\n",
    "                addresses[pid] = (pub_ip, port)\n",
    "    assert all([node is not None for node in addresses])\n",
    "except FileNotFoundError or AssertionError as e:\n",
    "    traceback.print_exc()\n",
    "\n",
    "print(addresses)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3.7.13 ('hbb')",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.13"
  },
  "orig_nbformat": 4,
  "vscode": {
   "interpreter": {
    "hash": "7f5c99d094b399fa9e65cc4107643c6d5293cb8e1c21c8f7db515a0780c667bb"
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
